package com.mxf.code.chain_params;

import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author 28382
 */
@Component
@Order(0)
public class BooleanValidHandler extends DataValidHandler<Boolean> {

    @Override
    public Result<Void> ruleVerification(String key, ParamRequest paramRequest) {
        // 判断是否必填
        boolean isRequired = paramRequest.isRequired();
        if (isRequired && Objects.isNull(paramRequest.getValue())) {
            return new Result<Void>().error("Value of " + key + " is required");
        }
        return new Result<>();
    }
}
